<template>
  <div class="add_table_css">
    <el-button plain @click="addQualify" class="btn_css_newadd">新增职业资格</el-button>
    <!-- 新增职业资格的弹框 -->
    <el-dialog title="新增职业资格" :visible.sync="dialogFormVisible" width="40%" center>
      <el-form
        label-width="110px"
        :model="workQtable"
        :rules="rules"
        ref="workQtable"
        class="demo-ruleForm add_education_css"
      >
        <el-form-item label="专业技术系列" prop="professionSeries">
          <el-input v-model="workQtable.professionSeries"></el-input>
        </el-form-item>
        <el-form-item label="资格名称" prop="name">
          <el-input v-model="workQtable.name"></el-input>
        </el-form-item>
        <el-form-item label="资格级别" prop="level">
          <el-input v-model="workQtable.level"></el-input>
        </el-form-item>
        <el-form-item label="资格专业" prop="major">
          <el-input v-model="workQtable.major"></el-input>
        </el-form-item>
        <el-form-item label="资格证号码" prop="papers">
          <el-input v-model="workQtable.papers"></el-input>
        </el-form-item>
        <el-form-item label="获取资格途径" prop="obtainChannel">
          <el-select v-model="workQtable.obtainChannel">
            <el-option label="自学" value="自学"></el-option>
            <el-option label="报班" value="报班"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="取得时间" prop="obtainTime">
          <!-- <el-date-picker type="date" placeholder="1987-09-23" v-model="workQtable.obtainTime"></el-date-picker> -->
          <el-date-picker
              prop="obtainTime"
              v-model="workQtable.obtainTime"
              type="date"
              placeholder="选择日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="timestamp"
            ></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer add_footer_btn_css">
        <el-button plain @click="addOk('workQtable')" class="btn_css_bord">保存</el-button>
        <!-- <el-button plain @click="updateOk('workQtable3')" class="btn_css_bord">保存</el-button> -->
        <el-button plain @click="dialogFormVisible = false" class="btn_css_bord">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 表格 -->
    <el-container>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="name" label="资格名称" width="160"></el-table-column>
        <el-table-column prop="papers" label="资格证号码" width="120"></el-table-column>
        <el-table-column prop="obtainChannel" label="获取资格途径" width="200"></el-table-column>
        <el-table-column prop="level" label="级别" width="250"></el-table-column>
        <el-table-column prop="obtainTime" label="取得时间" width="100"></el-table-column>
        <el-table-column label="操作" width="250">
          <template slot-scope="scope">
            <el-button @click="see(scope.$index, tableData)" size="small" plain class="btn_css_er">查看</el-button>
            <el-button
              @click.native.prevent="update(scope.$index, tableData)"
              plain
              size="small"
              class="btn_css_er"
            >修改</el-button>
            <el-button
              @click.native.prevent="del(scope.$index, tableData)"
              plain
              size="small"
              class="btn_css_er"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-container>
    <!-- 查看职业资格的弹框 -->
    <el-dialog title="查看职业资格" :visible.sync="dialogFormVisible2" width="40%" center>
      <el-form
        label-width="110px"
        :model="workQtable2"
        :rules="rules"
        ref="workQtable2"
        class="demo-ruleForm add_education_css"
      >
        <el-form-item label="专业技术系列" prop="professionSeries">
          <el-input v-model="workQtable2.professionSeries" disabled></el-input>
        </el-form-item>
        <el-form-item label="资格名称" prop="name">
          <el-input v-model="workQtable2.name" disabled></el-input>
        </el-form-item>
        <el-form-item label="资格级别" prop="level">
          <el-input v-model="workQtable2.level" disabled></el-input>
        </el-form-item>
        <el-form-item label="资格专业" prop="major">
          <el-input v-model="workQtable2.major" disabled></el-input>
        </el-form-item>
        <el-form-item label="资格证号码" prop="papers">
          <el-input v-model="workQtable2.papers" disabled></el-input>
        </el-form-item>
        <el-form-item label="获取资格途径" prop="obtainChannel">
          <el-input v-model="workQtable2.obtainChannel" disabled></el-input>
        </el-form-item>
        <el-form-item label="取得时间" prop="obtainTime">
          <el-input v-model="workQtable2.obtainTime" disabled></el-input>
          <!-- <el-date-picker type="date" placeholder="1987-09-23" v-model="workQtable2.obtainTime"></el-date-picker> -->
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 修改职业资格的弹框 -->
    <el-dialog title="修改职业资格" :visible.sync="dialogFormVisible3" width="40%" center>
      <el-form
        label-width="110px"
        :model="workQtable3"
        :rules="rules"
        ref="workQtable3"
        class="demo-ruleForm add_education_css"
      >
        <el-form-item label="专业技术系列" prop="professionSeries">
          <el-input v-model="workQtable3.professionSeries"></el-input>
        </el-form-item>
        <el-form-item label="资格名称" prop="name">
          <el-input v-model="workQtable3.name"></el-input>
        </el-form-item>
        <el-form-item label="资格级别" prop="level">
          <el-input v-model="workQtable3.level"></el-input>
        </el-form-item>
        <el-form-item label="资格专业" prop="major">
          <el-input v-model="workQtable3.major"></el-input>
        </el-form-item>
        <el-form-item label="资格证号码" prop="papers">
          <el-input v-model="workQtable3.papers"></el-input>
        </el-form-item>
        <el-form-item label="获取资格途径" prop="obtainChannel">
          <el-select v-model="workQtable3.obtainChannel">
            <el-option label="自学" value="自学"></el-option>
            <el-option label="报班" value="报班"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="取得时间" prop="obtainTime">
          <!-- <el-date-picker type="date" placeholder="1987-09-23" v-model="workQtable3.obtainTime"></el-date-picker> -->
          <el-date-picker
              prop="obtainTime"
              v-model="workQtable3.obtainTime"
              type="date"
              placeholder="选择日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="timestamp"
            ></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer add_footer_btn_css">
        <el-button plain @click="updateOk('workQtable3')" class="btn_css_bord">保存</el-button>
          <!-- <el-button plain @click="updateOk('qualifyTable2')" class="btn_css_bord">保存</el-button> -->
        <el-button plain @click="dialogFormVisible3 = false" class="btn_css_bord">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 分页 -->
    <div class="block page_css">
      <el-pagination layout="prev, pager, next" 
      :total="total"
      :page-size="limit"
      @current-change="change"
      @prev-click="prev"
      @next-click="next"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      page: 1,
      limit: 5,
      total: 0,
      staffId: 5,

      dialogFormVisible: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      tableData: [],
      workQtable: {
        professionSeries: "",
        name: "",
        level: "",
        major: "",
        papers: "",
        obtainChannel: "",
        obtainTime: ""
      },
      workQtable2: {
        professionSeries: "",
        name: "",
        level: "",
        major: "",
        papers: "",
        obtainChannel: "",
        obtainTime: ""
      },
      workQtable3: {
        professionSeries: "",
        name: "",
        level: "",
        major: "",
        papers: "",
        obtainChannel: "",
        obtainTime: ""
      },
      rules: {
        professionSeries: [{ required: true, message: "请输入毕业院校", trigger: "blur" }],
        name: [{ required: true, message: "请输入毕业院校", trigger: "blur" }],
        level: [{ required: true, message: "请输入毕业院校", trigger: "blur" }],
        major: [{ required: true, message: "请输入毕业院校", trigger: "blur" }],
        papers: [{ required: true, message: "请输入毕业院校", trigger: "blur" }],
        obtainTime: [
          { required: true, message: "请选择入学时间", trigger: "change" }
        ],
        obtainChannel: [{ required: true, message: "请选择学位", trigger: "change" }]
      }
    };
  },
  methods: {
    /* 页面渲染 */
    getCon() {
      this.$axios({
        url: "/qualifications/list",
        params: {
          page: this.page,
          limit: this.limit,
          staffId: this.staffId
        }
      }).then(res => {
        // console.log(res.data.data);
        this.tableData = res.data.data;
        this.total = res.data.count;
      });
    },
    /* 分页渲染 */
    change(page) {
      this.page = page;
      this.getCon();
    },
    prev() {
      this.page--;
      this.getCon();
    },
    next() {
      this.page++;
      this.getCon();
    },
    /* 新增渲染 */
    addQualify() {
      this.dialogFormVisible = true;
    },  
    addOk(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          // alert("submit!");
          this.$axios({
            url: "/qualifications/add",
            method: "post",
            data: {
              staffId: this.staffId,
              name: this.workQtable.name,
              papers: this.workQtable.papers,
              obtainChannel: this.workQtable.obtainChannel,
              level: this.workQtable.level,
              obtainTime: this.workQtable.obtainTime,
              professionSeries: this.workQtable.professionSeries,
              major: this.workQtable.major
            }
          }).then(res => {
            console.log(res);
            if (res.status == 200) {
              this.$message.success("添加成功！");
              this.getCon();
              this.dialogFormVisible = false;
            } else {
              this.$message.error("添加失败！");
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    /* 修改渲染 */
    update(index, data) {
      console.log(data);
      this.dialogFormVisible3 = true;
      this.workQtable3 = { ...data[index] };
    },
    updateOk(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$axios({
            url: "/qualifications/update",
            method: "post",
            data: {
              id:this.workQtable3.id,
              name: this.workQtable3.name,
              level: this.workQtable3.level,
              papers: this.workQtable3.papers,
              obtainChannel: this.workQtable3.obtainChannel,
              obtainTime: this.workQtable3.obtainTime,
              professionSeries: this.workQtable.professionSeries,
              major: this.workQtable.major
            }
          }).then(res => {
            console.log(res);
            this.getCon();
            this.dialogFormVisible3 = false;
          });

        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    /* 删除渲染 */
    del(index, data) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$axios({
          url:'/qualifications/delete',
          method:'post',
          data:{
            id:data[index].id,
          }
        }).then(res => {
          // console.log(res);
          this.getCon();
          this.$message.success('删除成功！');
          
        })
      })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },

    /* 查看 */
    see(index, data) {
      this.dialogFormVisible2 = true;   
      this.workQtable2 = { ...data[index]};
    },

  

    save() {
      this.dialogFormVisible = false;
    },
    save3() {
      this.dialogFormVisible3 = false;
    },
    
  },
  mounted(){
    this.getCon();
  }
 
};
</script>
<style scoped lang="less">
.page_css {
  margin: 10px;
  text-align: right; 
}
.el-table {
  font-size: 13px;
}
.add_table_css {
  border: 1px solid #eee;
  height: 600px;
  padding: 20px;
}
.btn_css_newadd {
  background-color: #f7f7f7;
  border: 1px solid #eee;

  text-align: center;
}
.btn_css_er {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  width: 60px;
  height: 30px;
  text-align: center;
}
.btn_css_bord {
  background-color: #f7f7f7;
  border: 1px solid #eee;
  width: 80px;
  height: 40px;
  font-size: 14px;
  text-align: center;
}

.add_education_css {
  width: 300px;
  margin: 0 auto;
  .el-date-picker {
    width: 100px !important;
  }
}
.add_footer_btn_css {
  margin: 0 auto;
}
</style>